﻿using MyCrawler.Forums;
using MyCrawler.Entity;
using MyCrawler.Utilyties;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCrawler.Dals
{
    class ForumCommentDal
    {
        internal string _cn;

        internal ForumCommentDal()
        {
            _cn = UtilityCtr.GetConnectString();
        }

        /// <summary>
        /// Thêm mới 1 bình luận
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        internal void Insert(ForumCommentEntity obj)
        {
            using (SqlConnection con = new SqlConnection(_cn))
            {
                try
                {
                    con.Open();

                    string q = "INSERT INTO [ForumComment]([IdTopic],[Comment],[PostDate],[Username],[Avatar]) VALUES ('" + obj.IdTopic + "'";

                    q += ",N'" + obj.Comment.Replace("'", "''") + "'";
                    q += ",'" + obj.PostDate.ToString("yyyy-MM-dd hh:mm:ss") + "'";
                    q += ",N'" + obj.Username.Replace("'", "''") + "'";
                    q += ",N'" + obj.Avatar.Replace("'", "''") + "'";
                    q += ") ";

                    SqlCommand cmd = new SqlCommand(q, con);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex) { }
            }
        }
    }
}
